package com.cskaoyan.wordmemorize.controller.admin;


import com.cskaoyan.wordmemorize.common.result.Result;
import com.cskaoyan.wordmemorize.dto.admin.LevelPrivilegeDTO;
import com.cskaoyan.wordmemorize.dto.admin.PageDTO;
import com.cskaoyan.wordmemorize.request.BatchDeleteCommand;
import com.cskaoyan.wordmemorize.request.LevelPrivilegeCommand;
import com.cskaoyan.wordmemorize.request.LevelPrivilegePageRequest;
import com.cskaoyan.wordmemorize.service.LevelPrivilegeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;



@RestController
@RequestMapping("/admin/privilege")
public class AdminLevelPrivilegeController {

    @Autowired
    LevelPrivilegeService levelPrivilegeService;


    // todo 添加等级特权(后台等级权限管理-特权管理)
    @PostMapping("")
    public Result addLevelPrivilege(@RequestBody LevelPrivilegeCommand command) {
        levelPrivilegeService.addLevelPrivilege(command);
        return Result.ok();
    }


    // todo 更新等级特权(后台等级权限管理-特权管理)
    @PutMapping("")
    public Result updateLevelPrivilege(@RequestBody LevelPrivilegeCommand command) {
        levelPrivilegeService.updateLevelPrivilege(command);
        return Result.ok();
    }

    // todo 删除等级特权(后台等级权限管理-特权管理)
    @DeleteMapping("{id}")
    public Result deleteLevelPrivilege(@PathVariable("id") Long id) {

        levelPrivilegeService.deleteLevelPrivilege(id);
        return Result.ok();

    }

    // todo 批量删除更新等级特权(后台等级权限管理-特权管理)
    @DeleteMapping("batch")
    public Result batchDeleteLevelPrivilege(@RequestBody BatchDeleteCommand command){

        levelPrivilegeService.batchDeleteLevelPrivilege(command);

        return Result.ok();
    }


    // todo 分页查询(后台等级权限管理-特权管理)
    @GetMapping("list")
    public Result<PageDTO<LevelPrivilegeDTO>> getLevelPrivilegeList( LevelPrivilegePageRequest pageRequest){

        PageDTO<LevelPrivilegeDTO> pageDTO = levelPrivilegeService.getLevelPrivilegeList(pageRequest);
        return  Result.ok(pageDTO);

    }

}
